<template>
	<view class="page">
		<view class="ver bgf5 px40 flex flexC flexCol flexJC" >
			<view class="flex flexC mt-50">
				<image class="w38" src="/static/img/icon/meituan.png" mode="aspectFill"></image>
				<image class="w38 ml3" src="/static/img/icon/dazong.png" mode="aspectFill"></image>
			</view>
			<view class="fs16 bold6 c00 mt20">美团、大众点评自助验券</view>
			<view class="mt30 flex flexC w-14 borb">
				<input type="text" class="flex1 pl10 py9" v-model="code" placeholder="点击输入卡券兑换码"
					placeholder-class="cbe" />
				<image @click="scan" class="w18 ml10 p10" src="/static/img/icon/scan.png" mode="aspectFill"></image>
			</view>
			<view @click="open" class="w-15 py10 bgf6c r40 flex flexC flexJC mt16">开台</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				code: '',
				id:'',
				isPaying:false,
				order_no:'',
				dou_code:''
			};
		},
		onLoad(option) {

			this.id = option.id;

		},
		methods: {
			
			open(){
				
				let param = {
					id: this.id,
					dou_code: this.dou_code,
					mt_code: this.code,
				};
				let that = this;
							
				if (this.isPaying == true) return;
				this.isPaying = true;
				this.$api.tableAddOrder(param).then(res => {
					console.info(JSON.stringify(res));
					that.isPaying = false;
					if (res.code == 1) {
						that.order_no = res.data.order_no;
						uni.redirectTo({
							url: '../order/tableDetail?order_no=' + that.order_no
						})
					} else {
						uni.showToast({
							icon: "none",
							title: res.msg
						})
					}
							
				})
			},

			scan() {
				console.info("===scan==");
				let that = this;
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						that.code = res.result;

					},
					fail: function(res) {

						console.info(res);
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.ver {
		height: 100vh;
		.w38 {
			width: 76rpx;
			height: 76rpx;
		}

		.w18 {
			width: 36rpx;
			height: 36rpx;
		}

		.mt-50 {
			margin-top: -400rpx;
			position: relative;
		}
	}
</style>